/*
#include <iostream>
#include <fstream>
#include <cerrno>
#include <string>

#include "tinyxml2.h"
#include "HTTPGet.hpp"
#include "XMLDiscover.hpp"
#include "YQLQuotes.hpp"

using namespace std;

// Forwards
std::string get_file_contents(const char *filename);


void testYQLQuotes()
{
   cout << "Starting testYQLQuotes\n-------------------\n";
   YQLQuotes yql;
   yql.addSymbol("YHOO");

   cout << "...Loading from YQL\n";
   if (!yql.loadFromYQL()) {
      cout << "testYQLQuotes() - Error loadFromYQL()!\n";
      return;
   }
   
   cout << "...Parsing XML\n";
   if (!yql.parseXML()) {
      cout << "testYQLQuotes() - Error parseXML()!\n";
      return;
   }
   
   cout << "...Iterating quotes\n";
   
   for ( int iQuote = 0; (unsigned)iQuote < yql.getNumQuotes(); ++iQuote) {
      ResultQuote quote;
      if (!yql.getQuote(iQuote, quote)) {  
	 cout << "testYQLQuotes() - Error getQuote()!\n";
	 return;
      }
	  
      cout << "\n--- Quote for " << quote.getSymbol() << " ---\n";
      for (int idx = 0; idx < quote.getPairCount(); ++idx) {
         FieldName fieldName = quote.getFieldNameFromVector(idx);
	 FieldValuePair valuePair;
	 if (!quote.getFieldValuePair(fieldName, valuePair)) {
	    cout << "testYQLQuotes() - Error getting field value pair.\n";
	    return;
	 }
	 cout << "   " << valuePair.getFieldNameString() << " ... " << valuePair.getValueString() << "\n";
      }
   } // for unsigned int
   
   cout << "\n======================\nTest done.\n";
}



void testDiscover()
{
   cout << "\nTest Discover\n===========================\n";
   std::string strURL = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20%28%22AAPL%22%29&env=store://datatables.org/alltableswithkeys";
  
   XMLDiscover disc;
   if (!disc.fetchPage(strURL)) {
      cout << "testDiscover() - Error fetching page.\n";
      return;
   }
   
   if (!disc.parseXMLData()) {
      cout << "testDiscover() - Error parsing XML.\n";  
      return;
  }

  cout << "\n... Relationship Count: \n" << disc.vecNames.size() << "\n";
  for (unsigned int i = 0; i < disc.vecNames.size(); ++i) {
     
     cout << "this->addRelationship(\"" << disc.vecNames[i] << "\",         FieldType::" 
          << disc.vecNames[i] << ");\n";
  }

  for (unsigned int i = 0; i < disc.vecNames.size(); ++i) {
      cout << disc.vecNames[i] << ", ";
  }
  
  cout << "\n===========================\n";  
}



int oldmain() 
{
   // fetchHistoricalData();
   //testXMLParse();
   //testDiscover();
   testYQLQuotes();
   return 0;
}






// Util functions
std::string get_file_contents(const char *filename)
{
   std::ifstream in(filename, std::ios::in | std::ios::binary);
   if (in)
   {
      std::string contents;
      in.seekg(0, std::ios::end);
      contents.resize(in.tellg());
      in.seekg(0, std::ios::beg);
      in.read(&contents[0], contents.size());
      in.close();
      return(contents);
   }
   throw(errno);
}
                                                         

*/
                                                         
                                                         
                                                         
/* Fetch historical stock data and output XML to file */
/*
void fetchHistoricalData()
{
   Historical hist;
   
   hist.addSymbol("YHOO");
   hist.setStartDate("2014-01-01");
   hist.setEndDate("2014-11-11");
   
   if (hist.fetchData()) {
      cout << "URL: " << hist.getURL() << "\n";
      cout << "Data:\n" << hist.getXML() << "\n";
      // Write file
      ofstream myFile;
      myFile.open("data.xml");
      myFile << hist.getXML();
      myFile.close();
      cout << "Wrote data.xml\n";
   } else {
      cout << "Error in hist.fetchData()\n";
   }
}

void testXMLParse() 
{
   string data;
   try {
      data = get_file_contents("data.xml");
   } catch (...) {
      cout << "   ---Error opening data.xml\n";
      return;
   }
   
   Historical hist;
   
   if (!hist.loadDataFromString(data)) {
      cout << "   ---Error loading from string\n";
      return;
   }
   cout << "   Data loaded from file.\n";

   cout << "Parsing file ...\n";
   hist.parseXMLData();   
   
   cout << "Map Items: " << hist.mapHistorical.size() << "\n";
   cout << "Parse errors: " << hist.getParseErrors() << "\n";
   
   for (Historical::MapHistorical::iterator itr = hist.mapHistorical.begin();
        itr != hist.mapHistorical.end();
        ++itr)
   {
      DRec_Historical rec = itr->second;
      cout << rec.record_date << " : " 
           << rec.open        << " : " 
           << rec.high        << " : " 
           << rec.low         << " : " 
           << rec.close       << " : " 
           << rec.adj_close   << " : " 
           << rec.volume
           << "\n";      
   }
   
}

*/